import {
  Controller,
  Get,
  Post,
  Body,
  Param,
  Delete,
  Put,
  Query,
} from '@nestjs/common';
import { DeviceService } from './device.service';

@Controller('devices')
export class DeviceController {
  constructor(private readonly deviceService: DeviceService) {}

  @Post()
  create(@Body() body) {
    return this.deviceService.create(body);
  }

  @Get()
  findAll(
    @Query('current') current: number = 1,
    @Query('pageSize') pageSize: number = 10,
    @Query('deviceType') deviceType?: string,
    @Query('deviceAddress') deviceAddress?: string,
  ) {
    return this.deviceService.findAll({
      current: Number(current),
      pageSize: Number(pageSize),
      deviceType,
      deviceAddress,
    });
  }

  @Get(':id')
  findOne(@Param('id') id: number) {
    return this.deviceService.findOne(id);
  }

  @Put(':id')
  update(@Param('id') id: number, @Body() body) {
    return this.deviceService.update(id, body);
  }

  @Delete(':id')
  remove(@Param('id') id: number) {
    return this.deviceService.remove(id);
  }
}
